package com.gy.edu.home;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

import com.gy.edu.R;
import com.gy.edu.base.BaseActivity;
import com.gy.edu.home.adapter.HomeAdapter;
import com.gy.edu.home.bean.HomeBean;
import com.gy.edu.util.AnimUtil;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 高岳 on 2016/12/27.
 * Describe:
 */
public class HomeDetailActivity extends BaseActivity {


    private PullToRefreshListView listView;
    private List<HomeBean> datas;
    private HomeAdapter adapter;
    private String[] titles1 = new String[]{"MCGS触摸屏的应用-标准按钮和指示灯的制作","机械手自动搬运装置的电气调试",
    "变频器控制传送带的运行","电子元件基础五步焊接法","两地控制灯电路","三相异步电动机正反转控制电路","数控车床刀架电气故障处理"};
    private String[] titles2 = new String[]{"电容器的故事","光纤的熔接"};
    private String[] titles3 = new String[]{"地铁运营调度","汽车ABS系统"};
    private String[] titles4 = new String[]{"识读建筑平面图"};
    private String[] titles5 = new String[]{"智慧农业大棚之光照系统"};
    private int[] ids1 = new int[]{R.mipmap.ic_img10,R.mipmap.ic_img11,R.mipmap.ic_img12,R.mipmap.ic_img13,R.mipmap.ic_img14,R.mipmap.ic_img15,R.mipmap.ic_img16};
    private int[] ids2 = new int[]{R.mipmap.ic_img20,R.mipmap.ic_img21};
    private int[] ids3 = new int[]{R.mipmap.ic_img30,R.mipmap.ic_img31};
    private int[] ids4 = new int[]{R.mipmap.ic_img40};
    private int[] ids5 = new int[]{R.mipmap.ic_img50};

    @Override
    protected void initView() {
        setContentViewRes(R.layout.activity_home_detail);
        listView = (PullToRefreshListView) findViewById(R.id.home_listview);
    }

    @Override
    protected void initData() {
        datas = new ArrayList<>();
        int position = getIntent().getIntExtra("position",0);
//        String[] titles = mContext.getResources().getStringArray(R.array.home_title);
        String[] titles = new String[]{};
        int[] ids = new int[]{};
        if(position == 0){
            titles = titles1;
            ids = ids1;
        } else if(position == 1){
            titles = titles2;
            ids = ids2;
        } else if(position == 2){
            titles = titles3;
            ids = ids3;
        } else if(position == 3){
            titles = titles4;
            ids = ids4;
        } else if(position == 4){
            titles = titles5;
            ids = ids5;
        } else if(position == 5){
        }

        String[] names = mContext.getResources().getStringArray(R.array.home_name);
        int[] numbers = mContext.getResources().getIntArray(R.array.home_number);
        int[] classs = mContext.getResources().getIntArray(R.array.home_class);
        for (int i = 0; i < titles.length; i++) {
            HomeBean bean = new HomeBean();
            bean.title = titles[i];
            bean.name = names[i];
            bean.number = numbers[i]+"";
            bean.classs = classs[i]+"";
            bean.img = ids[i];
            datas.add(bean);
        }
        adapter = new HomeAdapter(mContext,datas);
    }

    @Override
    protected void setListener() {
        super.setListener();
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(mContext,ClassDetailActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("bean",datas.get(position - 1));
                intent.putExtras(bundle);
                startActivity(intent);
                AnimUtil.pushLeftInAndOut(HomeDetailActivity.this);
            }
        });
    }

    @Override
    protected void fillData() {
        super.fillData();
        listView.setMode(PullToRefreshBase.Mode.DISABLED);
        listView.setAdapter(adapter);
    }
}
